package ace.handling;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;

import org.mitre.jawb.io.SgmlDocument;

public class CreateFileList {

	private static final String NATURAL_DISASTER = "NaturalDisaster";

	
	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		
		String[] Datasets = {"AFFILIATE-PARTNER","ASSOCIATE","AT","BASED-IN","CITIZEN-OF","CLIENT","FOUNDER","GENERAL-STAFF","GRANDPARENT",
				"LOCATED", "MANAGEMENT","MEMBER","NEAR","OTHER","OTHER-PERSONAL","OTHER-PROFESSIONAL","OTHER-RELATIVE","OWNER","PARENT",
				"PART","PART-OF","RELATIVE-LOCATION","RESIDENCE","ROLE","SIBLING","SOC","SPOUSE","SUBSIDIARY","NaturalDisaster"};
		
		for (int dataset = 0; dataset < Datasets.length; dataset++) {
			String datSetName = Datasets[dataset];
			
			int[] split = getSplit(datSetName);
			
			for (int spl = 0; spl < split.length; spl++) {
				
				String directory = getDirectory(datSetName) + spl + "/taggedtestingDirectory/";
				
				String testingdirectory = getDirectory(datSetName) + spl + "/testingDirectory/";
				
				new File(testingdirectory).mkdir();
				
				File dir = new File(directory);
				
				File[] files = dir.listFiles();
				
				String listFile = getDirectory(datSetName) + spl + "/testing_list";
				
				System.setOut(new PrintStream(new File(listFile)));
				
				for (File file : files) {
					
					System.out.println(file.getName());
					
					SgmlDocument doc = new SgmlDocument(new FileReader(file));
					
					BufferedWriter bw = new BufferedWriter(new FileWriter(new File(testingdirectory + file.getName())));
					
					bw.write(doc.getSignalText());
					
					bw.close();
					
				}
				
			}
			
		}
		
	}

	private static int[] getSplit(String dataset) {
		
		if (dataset.equals(NATURAL_DISASTER)){
			int[] ret = {0,1,2,3,4,5,6,7,8,9};
			return ret;
		}
		int[] ret = {0};
		return ret;

		
	}

	private static String getDirectory(String dataset) {
		if (dataset.equals(NATURAL_DISASTER)){
			return "/home/pjbarrio/Dataset/NaturalDisaster/RelatedData/reverbData/";
		}

		return "/home/pjbarrio/Dataset/SGML-ACE-COREF/" + dataset + "/";

	}

	
}
